package cn.lgy.basis.bean;

import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;

public class DataResult<T> implements Serializable {
    private static final long serialVersionUID = 1675455733501893074L;
    private long count;
    private T data;
    private int code;
    private String message;
    private String errorMessage;
    private String systemError;

    public long getCount() {
        return this.count;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return this.message == null ? "" : this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getErrorMessage() {
        return this.errorMessage == null ? "" : this.errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getSystemError() {
        return this.systemError;
    }

    public void setSystemError(Throwable throwable) {
        this.systemError = getStackTrace(throwable);
    }

    public DataResult() {
        this.code = 1;
    }

    public DataResult(long count, T data, int code, String message, String errorMessage, String systemError) {
        this.count = count;
        this.data = data;
        this.code = code;
        this.message = message;
        this.errorMessage = errorMessage;
        this.systemError = systemError;
    }

    public DataResult(long count, T data, int code, String message, String errorMessage, Throwable throwable) {
        this.count = count;
        this.data = data;
        this.code = code;
        this.message = message;
        this.errorMessage = errorMessage;
        this.systemError = getStackTrace(throwable);
    }

    public static <T> DataResult<T> of(T data) {
        return new DataResult(1L, data, 1, "获取数据成功", "", "");
    }

    public static <T> DataResult<T> of(T data, String message) {
        return new DataResult(1L, data, 1, message, "", "");
    }

    public static <T> DataResult<T> of(int code, T data, String message) {
        return new DataResult(1L, data, code, message, "", "");
    }

    public static <T> DataResult<T> of(long count, T data) {
        return new DataResult(count, data, 1, "获取数据成功", "", "");
    }

    public static <T> DataResult<T> of(long count, T data, String message) {
        return new DataResult(count, data, 1, message, "", "");
    }

    public static <T> DataResult<T> of(int code, long count, T data, String message) {
        return new DataResult(count, data, code, message, "", "");
    }

    public static <T> DataResult<T> of(String errorMessage) {
        return new DataResult(0L, (Object)null, 0, "", errorMessage, "");
    }

    public static <T> DataResult<T> of(String errorMessage, Throwable throwable) {
        return new DataResult(0L, (Object)null, 0, "", errorMessage, throwable);
    }

    public static <T> DataResult<T> of(int code, String errorMessage) {
        return new DataResult(0L, (Object)null, code, "", errorMessage, "");
    }

    public static <T> DataResult<T> of(int code, String errorMessage, Throwable throwable) {
        return new DataResult(0L, (Object)null, code, "", errorMessage, throwable);
    }

    public static <T> DataResult<T> of(int code, long count, T data, String message, String errorMessage, Throwable throwable) {
        return new DataResult(count, data, code, message, errorMessage, throwable);
    }

    protected static String getStackTrace(Throwable throwable) {
        if (throwable != null) {
            StringWriter errors = new StringWriter();
            throwable.printStackTrace(new PrintWriter(errors));
            return errors.toString();
        } else {
            return "";
        }
    }
}
